
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>增加终端</title>
		<%@ include file="/commons/css_js_head.jsp"%>
<script type="text/javascript">

//复写Url
doSaveUrl = "${ctx }/base/tsMachinesAction!doSave.ts";
doReturnUrl = "${ctx }/base/tsMachinesAction!doList.ts";
doAddBeforeUrl = "${ctx }/base/tsMachinesAction!doFindByOptionsId.ts";
//校验用户账号是否存在

//判断必填内容是否为空

function isExist(){
	//输入框
	var machinesCompCode = document.getElementById("machines.compCode");
	var machinesDeviceCode = document.getElementById("machines.deviceCode");
	var machinesDeviceRandom = document.getElementById("machines.deviceRandom");
	
	//提示信息Span
	var compCode = document.getElementById("compCode");
	var deviceCode = document.getElementById("deviceCode");
	var deviceRandom = document.getElementById("deviceRandom");
	
	//确定按钮
	var btn = document.getElementsByName("btn_confirm");
	
	if(
		machinesCompCode.value.replace(/(^\s*)|(\s*$)/g,"")!="" &&
		machinesDeviceCode.value.replace(/(^\s*)|(\s*$)/g,"")!="" && 
		machinesDeviceRandom.value.replace(/(^\s*)|(\s*$)/g,"")!=""   
	){
		$.ajax({
      type : "post",
      url : "${ctx }/base/tsMachinesAction!doCheckMachinesIsExist.ts",
      cache: false,
      data : "&compCode="+machinesCompCode.value+"&deviceCode="+machinesDeviceCode.value+"&deviceRandom="+machinesDeviceRandom.value,
      success : function(data){
      
      if( data == "true" )
       {
          // var innerHtml = "<span class='ts_red'>该机器码已经存在，请重新输入！<\/span>";
           //mesg.innerHTML=innerHtml;
           document.getElementById("deviceCode").innerHTML="<span class='ts_red'>该机器码已经存在，请重新输入！<\/span>";
          $("#confirmBtn").attr('disabled', true);
          
          
          
           return false;
        }
       else
       {
           var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
           deviceCode.innerHTML=innerHtml;
           $("#confirmBtn").attr('disabled', false);
          return true;
       }
      },
     error: function(){
     	   var innerHtml = "<span class='ts_red'>服务繁忙，请稍后再试！<\/span>";
           deviceCode.innerHTML=innerHtml;
           //txtObj.value = "";
           return false;
     	}
   });
	}
}



//验证厂家编号
function checkCompCode() {

	var machinesCompCode = document.getElementById("machines.compCode");
	var compCode = document.getElementById("compCode");
	
	var str = /^[\d\w]{12}$/
	
	if(!str.exec(machinesCompCode.value)){
		var innerHtml = "<span class='ts_red'>请输入6位的厂家编号！<\/span>";
		compCode.innerHTML = innerHtml;
		
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(compCode,innerHtml);
		//return true;
	}
	
	isExist();
	
}



//验证机器码
function checkDeviceCode() {

	var machinesDeviceCode = document.getElementById("machines.deviceCode");
	var deviceCode = document.getElementById("deviceCode");
	
	var str = /^[\d]{6}$/
	
	if(!str.exec(machinesDeviceCode.value)){
		var innerHtml = "<span class='ts_red'>请输入6位数字的机器码！<\/span>";
		deviceCode.innerHTML = innerHtml;
		//cleanData(machinesDeviceCode,deviceCode,innerHtml);
		return false;
	}
	//else{
	//	var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
	//	disInfo(deviceCode,innerHtml);
		//return true;
	//}
	isExist();
}



//验证设备名称
function checkName() {

	var machinesName = document.getElementById("machines.name");
	var name = document.getElementById("name");
	
	if(machinesName.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入设备名称！<\/span>";
		cleanData(machinesName,name,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(name,innerHtml);
		//return true;
	}
	
}






//保存
function doSave() {
	
	//输入框
	var machinesCompCode = document.getElementById("machines.compCode");
	var machinesDeviceCode = document.getElementById("machines.deviceCode");
	var machinesDeviceRandom = document.getElementById("machines.deviceRandom");
	var machinesName = document.getElementById("machines.name");
	
	var str1 = /^[\d\w]{6}$/
	var str2 = /^[\d]{6}$/
	
	var checkbox = document.getElementsByName("checkbox1");
	var asids = "";
	for(i=0;i<checkbox.length;i++){
      
         if( checkbox.item(i).checked){
         asids = asids+ checkbox[i].value+",";
       }
      }    
     //  alert(asids);   
	var _form = document.forms[0];
	if (doSaveUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
		//先判断必填内容是否为空
		//alert(machinesDeviceCode.value);
		if(
		machinesDeviceCode.value.replace(str2)!="" && 
		machinesName.value.replace(/(^\s*)|(\s*$)/g,"")!=""   
		){
		
	
		_form.action = doSaveUrl+"?selectRightList="+asids;
		_form.submit();
	}else {
		alert("带*号的内容请正确输入！");
		return false;
	}
}


//根据我的类型过滤
function doFindByOptionsId(optionsId) {
	
	//alert(optionsId.value);
	var _form = document.forms[0];
	if (doAddBeforeUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}else{
	
		_form.action = doAddBeforeUrl+"?optionsId="+optionsId.value;
		_form.submit();
	}
	
}

function addRowkv() { 
var confName = document.getElementById("confName").value; 
var confValue = document.getElementById("confValue").value; 
 
if(confName.replace(/[ ]/g,"") == "" ){
 alert("请输入正确的名称");
  document.getElementById("confName").focus();
  return;
}
if(confValue.replace(/[ ]/g,"") == ""){
 alert("请输入名称对应的值");
   document.getElementById("confValue").focus();
   return;
}

           //添加一行 
var newTr = fzjcTbl.insertRow(fzjcTbl.rows.length-1); 
//添加六列 
var newTd0 = newTr.insertCell(); 
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell(); 
var newTd3 = newTr.insertCell(); 
var newTd4 = newTr.insertCell(); 
//设置列内容和属性 

var tname = document.getElementById("confName").value;
var tvalue = document.getElementById("confValue").value;
newTd0.innerHTML = '<input type=checkbox  onClick="GetRow()" value="'+confName+"_"+confValue+',"  name="bizNumbershy" align="center" checked="true"/>名称：'; 
newTd1.innerHTML= '<input type=text name="tname" value="'+tname+'"  /><font color="red"></font>';
newTd2.innerHTML= "值："; 
newTd3.innerHTML= '<input type=text name="tvalue" value="'+tvalue+'"  /><font color="red"></font>';
newTd4.innerHTML= "<a href=# onclick='theDelHy()'>删除</a>";

document.getElementById("confName").value="";
document.getElementById("confValue").value="";
document.getElementById("confName").focus();

}

//删除单独一行
function theDelHy(){	
	var fzjcTbl = document.getElementById("fzjcTbl");
	cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex; 
	var ro = fzjcTbl.rows[cGetRow];
	//debugger;
	var rcn = ro.cells[2];
	var rcp = ro.cells[3];
	fzjcTbl.deleteRow(cGetRow);	  				
}
checkit  =  true;
 function   SelectAll()  {
 
   var checkbox = document.getElementById("checkbox1");      
      if (checkit)      
      {      
      for(i=0;i<checkbox.length;i++)
      
        checkbox.item(i).checked=true;   
        checkit = false;      
      }      
      else      
      {      
      for(i=0;i<checkbox.length;i++)      
        checkbox.item(i).checked=false;      
        checkit = true;      
      }      
}
</script>
<script language="JavaScript">
<%@ include file="../js/acceptChoose.js" %>
</script>
	</head>
	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">增加机器</b> 带
			<b class="fred"> * </b>号为必填项
		</div>

		<form action="/base/tsMachinesAction" method="post" id="addFrm">
		<s:hidden name="machines.dqM"></s:hidden>
		<s:hidden name="machines.compCode"></s:hidden>
		<s:hidden name="machines.deviceRandom"></s:hidden>
		<s:hidden name="machines.status" value="1"></s:hidden>
			<!--list -->
			<div class="mainAdd">
				<table class="addTable">


					<tr>
						<td colspan="4">
							<b class="fblue">硬件终端基本信息</b>
							
							<!-- 提示记录是否已经存在 -->
							<span id="mesg"></span>
						</td>
					</tr>
					
					
					
					<tr>
						<th>
							<b class="fred"> * </b> 机器码：
						</th>
						<td>
							<s:textfield name="machines.deviceCode" maxlength="6" theme="simple" onkeyup="value=value.replace(/[^\d]/g,'');checkDeviceCode()"></s:textfield>
							<span id="deviceCode"></span>
						</td>
						<th>
							<b class="fred">*</b> 设备名称：
						</th>
						<td>
							<s:textfield name="machines.name" maxlength="64" theme="simple" onblur="checkName()"></s:textfield>
							<span id="name"></span>
						</td>
						
					</tr>
					
					<tr>
				
						<th>
							<b class="fred"> * </b> 我的设备类型：
						</th>
						<td colspan="3">
							      <s:select
                                 theme="simple"
                                 name="machines.theIdMachine"
                                 list="#request.list" 
                                 cssStyle="width:183px;"				
                                 listKey="theIdMachine" 
                                 listValue="name"					          	
                			     id="select"
                			     onchange="doFindByOptionsId(this)">
							</s:select>
						</td>
				
						
					</tr>
					
					<tr>
						
						
						<th>
							 地址：
						</th>
						<td colspan="3">
							<s:textfield name="machines.address" maxlength="64" theme="simple" cssStyle="width:500px;"></s:textfield>
						</td>
					</tr>
				</table>
				
			 <table class="listTable">
				<tr>
					<th>选择<input type="checkbox" name="all" onclick="SelectAll()"/></th>
					<th>序号</th>
					<th>
						应用名称
					</th>
					<th>
						接口类型
					</th>
					<th>
						接口地址
					</th>
					<th>
						接口参数
					</th>
					
					<th>
						地址
					</th>
					
				</tr>

				<c:forEach var="appServer" varStatus="status" items="${resList}">
					<tr align=center>
						<td><input type="checkbox" checked="checked" id="checkbox1" name="checkbox1" value="${appServer.asid }" /> </td>
						<td>${status.index+1}</td>
						<td>
						
							${appServer.name}
						</td>
						<td>
							<c:if test="${appServer.interType == '0'}">  <span>Socket</span> </c:if>
						    <c:if test="${appServer.interType == '1'}">  <span>Webservice</span> </c:if>
						    <c:if test="${appServer.interType == '2'}">  <span>Http</span> </c:if>
						</td>
						<td>
							${appServer.interAddress }
						</td>
						<td>
							${appServer.interMethod }
						</td>
						<td>
							${appServer.address}
						</td>
						
					</tr>
				</c:forEach>

			</table>
			</div>
			<!--end list -->
			<div class="addToolbar">
				<p>
					<input class="btn" name="btn_confirm" value="确定" type="button" id="confirmBtn"
						onclick="doSave();" />
					<input class="btn" name="btn_return" value="返回" type="button"
						onclick="doReturn();" ; />
				</p>
			</div>

		</form>

	</body>

<script type="text/javascript">
//document.getElementById("machines.compCode").focus();

document.onkeydown = function(e) {
	if (!e)
		e = window.event;//火狐中是 window.event
	if ((e.keyCode || e.which) == 13) {
		doSave();
	}
}
</script>
</html>
